import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

Vue.config.productionTip = false


// 引入 css
import '@/assets/css/animate.css'
import '@/assets/css/typo.css';
import '@/assets/css/prism.css'
import '@/assets/css/global.css'


//1、引入 element-ui
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);


//2、引入 axios
import axios from "axios";
Vue.prototype.$http = axios

//设置基本访问路径
const basic = axios.create({
  baseURL: 'http://localhost:8888/yumWebsite'
})
Vue.prototype.$basic = basic
// 博客后台api地址
const blog = axios.create({
  baseURL: 'http://localhost:8888/yumWebsite/blog'
})
Vue.prototype.$blog = blog
//管理员api地址
const admin = axios.create({
  baseURL: 'http://localhost:8888/yumWebsite/admin'
})
Vue.prototype.$admin = admin


// 导入 highlight.js
import hljs from 'highlight.js'
import 'highlight.js/styles/googlecode.css' //样式文件
Vue.directive('highlight',function (el) {
  let blocks = el.querySelectorAll('pre code');
  blocks.forEach((block)=>{
    hljs.highlightBlock(block)
  })
})


//导入 md5 密码格式转换
import md5 from 'js-md5'
Vue.prototype.$md5 = md5;


//导入辅助跨域请求的 jsonp : vue-jsonp
import {VueJsonp} from 'vue-jsonp'
Vue.prototype.$jsonp = VueJsonp
Vue.use(VueJsonp)


// 配置时间格式化过滤器
Vue.filter('dataFormat', function (originVal) {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')
  return `${y}-${m}-${d}`
})

Vue.filter('dataFormat2', function (originVal) {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')
  return `${y}-${m}`
})

Vue.filter('dataFormat3', function (originVal) {
  const dt = new Date(originVal)
  let usedTime = new Date() - dt
  let days = Math.floor(usedTime / (24 * 3600 * 1000)); // 计算出天数
  let leavel = usedTime % (24 * 3600 * 1000); // 计算天数后剩余的时间
  let hours = Math.floor(leavel / (3600 * 1000)); // 计算剩余的小时数
  let leavel2 = leavel % (3600 * 1000); // 计算剩余小时后剩余的毫秒数
  let minutes = Math.floor(leavel2 / (60 * 1000)); // 计算剩余的分钟数
  if (days > 0) return days + '天前'
  if (hours > 0) return hours + '小时前'
  return minutes + '分前'
})

Vue.filter('dataFormat4', function (originVal) {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')
  const h = (dt.getHours()+ '').padStart(2, '0')
  const M = (dt.getMinutes()+ '').padStart(2, '0')
  const s = (dt.getSeconds()+ '').padStart(2, '0')
  return `${y}-${m}-${d} ${h}:${M}:${s}`
})


//引入 echarts
import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts


//引入 markdown 编辑器
import mavonEditor from 'mavon-editor'
Vue.use(mavonEditor)
import 'mavon-editor/dist/css/index.css'  //这里引入样式，可以正常显示编辑区导航栏

//引入 marked 解析器
import marked from 'marked'
Vue.prototype.$marked = marked


//引入 jquery
import $ from 'jquery'

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
